<?php



include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");

include_once($_SERVER["DOCUMENT_ROOT"] . "/include/user/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/mblog/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/gonglue/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();

function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//check refer  -  add by xinwei
	if(! security_check::check_refer())
	{
		throw new Exception("来路不明");
	}
	
	
	cgi::both($g_cgival["id"], "id", 0);
	$g_cgival["id"] = intval($g_cgival["id"]);
	cgi::both($g_cgival["url"], "url", 0);
	$g_cgival["url"] = string::un_html($g_cgival["url"]);
	
	
	cgi::both($g_cgival["topic_id"], "topic_id", 0);
	$g_cgival["topic_id"] = intval($g_cgival["topic_id"]);
	
	cgi::both($g_cgival["get_type"], "get_type", 0);
	$g_cgival["get_type"] = intval($g_cgival["get_type"]);
	
	cgi::both($g_cgival["type"], "type","add");
	
	cgi::both($g_cgival["content_type"], "content_type", 0);
	$g_cgival["content_type"] = intval($g_cgival["content_type"]);

}

function get_data()
{
	global $g_cgival, $g_pro, $g_show,$config;
	
	
	
	$topic_id = $g_cgival["topic_id"];
	$url = $g_cgival["url"];
	$get_type = $g_cgival["get_type"];
	$id = $g_cgival["id"];
	$type = $g_cgival["type"];
	$content_type = $g_cgival["content_type"] ;
	if($type == "add")
	{
		if($id)
		{
			$db_gonglue_cron_topic = new db_gonglue_cron_topic();
			$db_gonglue_cron_topic->admin_update_gonglue_cron_topic($id,$topic_id,$url,$get_type,$content_type);
		}
		else
		{
			$db_gonglue_cron_topic = new db_gonglue_cron_topic();
			$db_gonglue_cron_topic->admin_insert_gonglue_cron_topic($topic_id,$url,$get_type,$content_type);
			
		}
		
	}
	elseif($type == "del")
	{
		$db_gonglue_cron_topic = new db_gonglue_cron_topic();
		$db_gonglue_cron_topic->admin_del_gonglue_cron_topic($id);
	}
	
	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';
try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album_list.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
	{
		print_r($g_show);
		exit;
	}
	
	
	echo json_encode($g_show);
}

